import Table from '../../table'
import XEUtils from 'xe-utils'
import GlobalConfig from '../../conf'
import vSize from '../../mixins/size'
import platform from '../../table/src/platformMixins'
import VCUTable from '../../v-c-u-table'
import { UtilTools, DomTools, GlobalEvent } from '../../tools'

const methods = {}
const propKeys = Object.keys(Table.props)


function getTableOns(_vm) {
  const { $listeners } = _vm
  const ons = {}
  XEUtils.each($listeners, (cb, type) => {
    ons[type] = (...args) => {
      _vm.$emit(type, ...args)
    }
  })
  return ons
}

Object.keys(Table.methods).forEach(name => {
  methods[name] = function (...args) {
    return this.$refs.gridTable && this.$refs.gridTable[name](...args)
  }
})

export default {
  name: 'VcuGrid',
  mixins: [vSize, platform],
  props: {
    ...Table.props,
  },
  data() {
    return {
    }
  },
  computed: {
    tableExtendProps() {
      const rest = {}
      propKeys.forEach(key => {
        rest[key] = this[key]
      })
      return rest
    },
    tableProps() {
      const { tableExtendProps } = this
      const tableProps = Object.assign({}, tableExtendProps)
      return tableProps
    }
  },
  watch: {
  },
  created() {
  },
  mounted() {
  },
  destroyed() {
  },
  render(h) {
    const { $scopedSlots } = this
    return h('div', {
      class: ['vcu-grid', {
        'is--animat': !!this.animat,
        'is--round': this.round,
      }],
    }, [
      /**
       * 渲染表格
       */
      h('vcu-table', {
        props: this.tableProps,
        on: getTableOns(this),
        scopedSlots: $scopedSlots,
        ref: 'gridTable'
      })

    ])
  },
  methods: {
    ...methods,
  }
}